package com.dotflat.physicalevaluate.repository;

import com.dotflat.physicalevaluate.domain.pe.Measure;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

@CacheConfig(cacheNames = "EvaluateV2ItemRepository")
public interface MeasureRepository extends JpaRepository<Measure, String>, JpaSpecificationExecutor<Measure> {

//    @Column(columnDefinition = "INT DEFAULT 0 COMMENT '测评类型'")
//    private Integer evaluate;
//
//    @Column(columnDefinition = "varchar(32) DEFAULT 0 COMMENT '测评维度ID'")
//    private String dimensionId;
//
//    @Column(columnDefinition = "INT DEFAULT 0 COMMENT '性别'")
//    private Integer gender;
//
//    @Column(columnDefinition = "INT DEFAULT 0 COMMENT '月龄低'")
//    private Integer ageLow;
//
//    @Column(columnDefinition = "INT DEFAULT 0 COMMENT '月龄高'")
//    private Integer ageHigh;
//
//    @Column(name = "unit",columnDefinition = "INT DEFAULT 0 COMMENT '单位'", nullable = false)
//    private String unit;
//
//    @Column(columnDefinition = "INT DEFAULT 0 COMMENT '测试结果低'")
//    private Integer measureLow;
//
//    @Column(columnDefinition = "INT DEFAULT 0 COMMENT '测试结果高'")
//    private Integer measureHigh;

    @Query(value =
            "SELECT t.*  " +
            "FROM   pe_measure t  " +
            "WHERE " +
            "   t.dimensionId = :dimensionId and t.gender = :gender " +
                    " and :reserve >= t.reserveLow and :reserve < t.reserveHigh " +
                    " and :testVal >= t.measureLow and :testVal <= t.measureHigh " +
            "limit 1 ", nativeQuery = true)
    Measure findMeasureBy(@Param("dimensionId") String dimensionId,
                          @Param("gender") Integer gender,
                          @Param("reserve") Double reserve,
                          @Param("testVal") Double testVal);

//    @Cacheable(keyGenerator = "keyGenerator")

}